package com.example.collegevice.mapper;


import com.example.pojo.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface TeacherMapper {
    @Insert("insert into teacher(username, password, name,sex, title,  speciality_id, role,  avatar) " +
            "values(#{username}, #{password}, #{name},#{sex},  #{title}, #{specialityId}, #{role},#{avatar})")
    void insert(Teacher teacher);

    @Select("select * from teacher where username = #{username}")
    Teacher selectByUsername(String username);

//    @Select("select teacher.*, speciality.name as specialityName from teacher left join speciality on teacher.speciality_id = speciality.id")
    @Select("select * from teacher")
    List<Teacher> selectAll();

//    @Select("select teacher.*, speciality.name as specialityName from teacher " +
//            "left join speciality on teacher.speciality_id = speciality.id " +
//            "where name like concat('%', #{name}, '%')")
    @Select("select * from teacher where name like concat('%', #{name}, '%')")
    List<Teacher> selectByName(String name);

    @Update("update teacher set username=#{username}, password=#{password}, role=#{role}, " +
            "avatar=#{avatar}, name=#{name}, sex=#{sex}, title=#{title}, speciality_id=#{specialityId} " +
            "where id = #{id}")
    void updateById(Teacher teacher);

    @Delete("delete from teacher where id = #{id}")
    void deleteById(Integer id);

    @Select("select * from teacher where id = #{id}")
    Teacher selectById(Integer id);
}
